import React, { Component, Fragment, useEffect } from 'react'
import {Message} from "element-react"
import {useLocation, useNavigate } from 'react-router-dom'
import Topbar from '../Topbar'
import Nagtivebar from '../Nagtivebar'
import Content from '../Content'
import './index.css'
import { connect, Provider } from 'react-redux'
import {createLoginAction} from '../../redux/actions/loginAction'
import store from "../../redux/store"
class ReallymainUI extends Component {
    componentDidMount(){
        console.log(param.state)
        // if(param.state.islogin||this.props.userinfo.login_state) {
        if(param) {
            Message.success({
                message:"登陆成功",
                duration: 1300
            })

        } else {
            Message.warning("请先登陆")
            setTimeout(() => {
                nagtive("/", {replace:true})
            }, 3000);
            
        }
    }
    render() {
        return (
            <div style={{paddingTop:"2%" , height:"100%"}}>
                <Topbar/>
                <div className='main-nag-con'>
                    <Nagtivebar/>
                    <Content/>
                </div>
            </div>
        )
    }
}

const Reallymain = connect(
    state => ({userinfo:state.login}) , 
    {
        useLogin:createLoginAction
    }
)(ReallymainUI)


var param
var nagtive
export default function Main(props) {
    param = useLocation()
    nagtive = useNavigate()
    return (
        <Provider store={store}>
            <Reallymain/>
        </Provider>
    )
}

